package com.j.lemon.learn.basic.io.bio;

import java.io.*;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author lijunjun
 * @Date 2020-02-26 12:14
 * @Description
 */
public class BIOClient {
    public static void main(String[] args) throws IOException {
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        for (int i = 0; i < 1; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Socket socket = new Socket("localhost",8089);
                        OutputStream outputStream = socket.getOutputStream();
                        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
                        PrintWriter printWriter = new PrintWriter(outputStreamWriter,true);
                        Thread.sleep(6000);
                        printWriter.print("client send:hahaha");


                        InputStream inputStream = socket.getInputStream();
                        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                        String s = bufferedReader.readLine();
                        System.out.println(s);
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });

        }


    }
}
